﻿
var rukou = {
    timer:null,
    message:"<div style='padding:20px;'><p>message</p><br/><p style='text-align:center;'><a href='javascript:;' onclick='TINY.box.hide();'><img src='/image/ok.png' /></a></p></div>",
    bindStyleChangeEvent: function() {
        $("#aStyleChange").unbind("click");
        $("#aStyleChange").click(function() {
            $("#stylechange").css('left', (document.documentElement.clientWidth - 500) / 2  + 'px');
            $("#stylechange").css('top', (document.documentElement.clientHeight - 300) / 2  + 'px');
            $("#stylechange").css('z-index', '100');
            TINY.box.show($('#stylechange').html(),0,0,0,0);
        });
    },
    bindAddEvent: function() {
        $("#aEntryAdding").unbind("click");
        $("#aEntryAdding").click(function() {
            if ($.cookie('rukoumvcEmail')) {
            var value = categories;
            var obj = eval('(' + value + ')');
            $("#category").empty();
            for (var i = 0; i < obj.categories.length; i++) {
                    var category = obj.categories[i];
                    var categoryid = category.replace("\"", "").split('-')[0];
                    var categoryname = category.replace("\"", "").split('-')[1];
                    $("#category").append("<option value=\"" + categoryid + "\">" + categoryname + "</option>");
                }
            }
            if ($.cookie('rukoumvcEmail')) {
                $("#category").attr("value", NDrag.selectedTab.elm.id.substring(4));
            }

            TINY.box.show($('#setting').html(),0,500,0,0);
            
            $('#tinycontent').find("#updateEntry").attr("style", "display:none;");
            $('#tinycontent').find("#submitEntry").attr("style", "display:inline;");
            $('#tinycontent').find("#setting > h3").text("添加入口");

            $('#tinycontent').find("#privateEntryId").attr("value", "");
            $('#tinycontent').find("#siteName").attr("value", "");
            $('#tinycontent').find("#siteURL").attr("value", "http://");
            $('#tinycontent').find("#color").attr("value", "black");
            $('#tinycontent').find("#siteName").attr("class", "black");
            $('#tinycontent').find("#description").attr("value", "");
            $('#tinycontent').find("#siteIcon").attr("src", "");

            $('#tinycontent').find("#color").change(function() {
                $('#tinycontent').find("#siteName").attr("class", $('#tinycontent').find("#color").attr("value"));
            });

            rukou.bindSubmitEntryEvent();
            return false;
        });
    },

    bindClickCountEvent: function() {
        $("a[id^='e']").unbind("click")
        $("a[id^='e']").click(function() {
            var id = this.id;
            $.ajax({
                type: "POST",
                url: "/Ajax/SetClickCount",
                data: { entryid: this.id.substring(1) },
                success: function(data, textStatus) {
                }
            });
        });
    },

   
    rukouModify:function(id){
        var value = categories;
            var obj = eval('(' + value + ')');
            $("#category").empty();
            for (var i = 0; i < obj.categories.length; i++) {
                var category = obj.categories[i];
                var categoryid = category.replace("\"", "").split('-')[0];
                var categoryname = category.replace("\"", "").split('-')[1];
                $("#category").append("<option value=\"" + categoryid + "\">" + categoryname + "</option>");
            }
            
            TINY.box.show($('#setting').html(),0,500,0,0);
            
            $('#tinycontent').find("#submitEntry").attr("style", "display:none;");
            $('#tinycontent').find("#updateEntry").attr("style", "display:inline;");
            $('#tinycontent').find("#setting > h3").text("修改入口");
            
            
            $('#tinycontent').find("#privateEntryId").attr("value", id);                      //入口的id
            $('#tinycontent').find("#siteName").attr("value", $.trim($("#" + id + " > div > span > span").text()));               //入口的名称
            
            var lotvalue = $("#" + id + " .displaynone").html().split('|');
            $('#tinycontent').find("#siteURL").attr("value",lotvalue[0]);                     //入口的链接
            $('#tinycontent').find("#color").attr("value", $("#" + id + " > div > span > span").attr("class"));                       //入口的名称的颜色
            $('#tinycontent').find("#category").attr("value", parseInt(lotvalue[2]));    //入口所属的分类
            $('#tinycontent').find("#siteName").attr("class", $("#" + id + " > div > span > span").attr("class")); 
            $('#tinycontent').find("#description").attr('value', $("#" + id + " > div > span").attr("title"));                 //入口的描述

            $('#tinycontent').find("#color").change(function() {
                $('#tinycontent').find("#siteName").attr("class", $('#tinycontent').find("#color").attr("value"));
            });
            
            rukou.bindUpdateEntryEvent();
            return false;
    },

    rukouDelete: function(categoryid) {
            if (confirm("删除这个入口")) {
                var id = this.id;
                $.ajax({
                    type: "POST",
                    url: "/Ajax/DeletePrivateEntry",
                    data: { entryid: $("#delete").attr("name") },
                    success: function(data, textStatus) {
                        $("#" + $("#delete").attr("name")).remove();
                        NDrag.init(categoryid);
                    }
                });
            }
            return false;
    },
    
    rukouChangePic: function(entryid,style) {
       $.get( "/Ajax/GetStylePic/" + entryid + "/" + style, function(data){
            TINY.box.show(data,0,800,500,0);
        });
       return false;
    },
    
    submitRukouPicChange:function(entryid,styleid){
        for(var i=0;i<$(".picchangebox > ul").children().length;i++){
            if($($(".picchangebox > ul").children()[i]).find("input").attr("checked")){
                
                $.ajax({
                    type: "POST",
                    url: "/Ajax/rukouPicChangeSubmit",
                    data: {
                        entryid: entryid,
                        styleid: styleid,
                        imageid: $($(".picchangebox > ul").children()[i]).find("span").html(),
                        imagesource: $($(".picchangebox > ul").children()[i]).find("img").attr("src")
                    },

                    success: function(data, textStatus) {
                        eval("data =" + data.toLocaleString());
                        TINY.box.hide();
                        $("#" + data["entryid"]).find("img").attr("src",data["imagesource"]);
                    }
                });
            }
            
        }
    },
    

    bindSubmitEntryEvent: function() {
        $('#tinycontent').find("#submitEntry").unbind("click");
        $('#tinycontent').find("#submitEntry").click(function() {
            if ($.cookie('rukoumvcEmail')) {
                if ($('#tinycontent').find("#siteName").attr('value') == "" || $('#tinycontent').find("#siteURL").attr('value') == "") {
                    alert("网站名或者网址不能为空");
                    return false;
                }
                $('#tinycontent').find("#waiting").toggle();
                $('#tinycontent').find("#submitEntry").attr("disabled", "true");
                $.ajax({
                    type: "POST",
                    url: "/Ajax/SubmitPrivateEntry",
                    data: {
                        siteName: $('#tinycontent').find("#siteName").attr('value'),
                        siteURL: $('#tinycontent').find("#siteURL").attr('value'),
                        color: $('#tinycontent').find("#color").attr('value'),
                        categoryId: $('#tinycontent').find("#category").attr('value'),
                        description: $('#tinycontent').find("#description").attr('value')
                    },

                    success: function(data, textStatus) {
                        eval("data =" + data.toLocaleString());

                        $('#tinycontent').find("#waiting").toggle();
                        $('#tinycontent').find("#submitEntry").removeAttr("disabled");

                        if($("#rukoustyle").attr("value") == "simple"){
                            var newEntry = "<div class='cell' id='" + data["siteId"] + "'>";
                            newEntry += "<div class='displaynone'>" + data["siteURL"] + "|" + data["siteId"] + "|" + data["categoryId"] + "</div>";
                            newEntry += "<div style='cursor:pointer;' style='z-index:0;'><span class='t' title='" + data["description"] + "'><img src='" + data["icon"] + "' width='16px' height='16px'/>";
                            newEntry += "<span class='blue'>" + data["siteName"] +"</span></span></div></div>";
                            
                        }else if($("#rukoustyle").attr("value") == "span"){
                            var newEntry = "<div class='span-cell' id='" + data["siteId"] + "'>";
                            newEntry += "<div class='displaynone'>" + data["siteURL"] + "|" + data["siteId"] + "|" + data["categoryId"] + "</div>";
                            newEntry += "<div style='cursor:pointer;' style='z-index:0;'><span class='t' title='" + data["description"] + "'><img src='" + data["icon"] + "'/>";
                            newEntry += "<span class='blue'>" + data["siteName"] +"</span></span></div></div>";
                        }else if($("#rukoustyle").attr("value") == "round"){
                            var newEntry = "<div class='round-cell' id='" + data["siteId"] + "'>";
                            newEntry += "<div class='displaynone'>" + data["siteURL"] + "|" + data["siteId"] + "|" + data["categoryId"] + "</div>";
                            newEntry += "<div style='cursor:pointer;' style='z-index:0;'><span class='t' title='" + data["description"] + "'><img src='" + data["icon"] + "'/>";
                            newEntry += "<span class='blue'>" + data["siteName"] +"</span></span></div></div>";
                        }
                       

                        $("#privateEntries" + data["categoryId"]).append(newEntry);
                        NDrag.init(data["categoryId"]);
                        
                        $('#tinycontent').find("#description").attr('value', '');

                        TINY.box.hide();
                    }
                });
            }
            else {
                TINY.box.show(rukou.message.replace("message","需要登录以后才能添加网站到您的上网入口"),0,0,0,0);
            }
            return false;
        });
    },
    

    bindUpdateEntryEvent: function() {
        $('#tinycontent').find("#updateEntry").unbind("click");
        $('#tinycontent').find("#updateEntry").click(function() {
            if ($('#tinycontent').find("#siteName").attr('value') == "" || $('#tinycontent').find("#siteURL").attr('value') == "") {
                alert("网站名或者网址不能为空");
                return false;
            }
            $('#tinycontent').find("#waiting").toggle();
            $('#tinycontent').find("#updateEntry").attr("disabled", "true");

            var itemInfo = $("#" + $('#tinycontent').find("#privateEntryId").attr('value') + " .displaynone").html().split('|');
            var oldCategoryId = itemInfo[2];

            $.ajax({
                type: "POST",
                url: "/Ajax/UpdatePrivateEntry",
                data: { entryId: $('#tinycontent').find("#privateEntryId").attr('value'),
                    siteName: $('#tinycontent').find("#siteName").attr('value'),
                    siteURL: $('#tinycontent').find("#siteURL").attr('value'),
                    color: $('#tinycontent').find("#color").attr('value'),
                    categoryId: $('#tinycontent').find("#category").attr('value'),
                    description: $('#tinycontent').find("#description").attr('value')
                },

                success: function(data, textStatus) {
                    eval("data =" + data.toLocaleString());

                    $('#tinycontent').find("#waiting").toggle();
                    $('#tinycontent').find("#updateEntry").removeAttr("disabled");

                    if($("#rukoustyle").attr("value") == "simple"){
                        $("#" + data["siteId"] + " > div > span > span").html(data["siteName"]);
                        $("#" + data["siteId"]  + " > div > span > img").attr("src",data["icon"]);
                        $("#" + data["siteId"]+ " > div > span > span").attr("class", data["color"]);
                        $("#" + data["siteId"] + " > div > span").attr("title", data["description"]);
                        $('#tinycontent').find("#" + $("#privateEntryId").attr('value') + " .displaynone").html(data["siteURL"] + '|' + data["siteId"] + '|' + data["categoryId"]);
                    }else if($("#rukoustyle").attr("value") == "span"){
                        $("#" + data["siteId"] + " > div > span > span").html(data["siteName"]);
                        $("#" + data["siteId"]  + " > div > span > img").attr("src",data["icon"]);
                        $("#" + data["siteId"]+ " > div > span > span").attr("class", data["color"]);
                        $("#" + data["siteId"] + " > div > span").attr("title", data["description"]);
                        $('#tinycontent').find("#" + $("#privateEntryId").attr('value') + " .displaynone").html(data["siteURL"] + '|' + data["siteId"] + '|' + data["categoryId"]);
                    }else if($("#rukoustyle").attr("value") == "round"){
                        $("#" + data["siteId"] + " > div > span > span").html(data["siteName"]);
                        $("#" + data["siteId"]  + " > div > span > img").attr("src",data["icon"]);
                        $("#" + data["siteId"]+ " > div > span > span").attr("class", data["color"]);
                        $("#" + data["siteId"] + " > div > span").attr("title", data["description"]);
                        $('#tinycontent').find("#" + $("#privateEntryId").attr('value') + " .displaynone").html(data["siteURL"] + '|' + data["siteId"] + '|' + data["categoryId"]);
                    }

                    if (oldCategoryId != data["categoryId"]) {
                        $("#privateEntries" + data["categoryId"]).append($("#" + data["siteId"]));
                        NDrag.init(oldCategoryId);
                    }

                    $('#tinycontent').find("#description").attr('value', '');
                    
                    TINY.box.hide();
                }
            });
            return false;
        });

    },

    bindAddPrivateEntry: function() {
        $("a[id^='td']").unbind("click")
        $("a[id^='td']").click(function() {
            var id = this.id;
            var EntryId = this.id.substring(2);
            $.ajax({
                type: "POST",
                url: "/Ajax/AddFromSelector",
                data: { entryid: EntryId },
                success: function(data, textStatus) {
                    $("#" + id).parent().remove();
                    $("#message").toggle();
                    setTimeout("$(\"#message\").toggle();", 2000);
                }
            });
            return false;
        });

    },

    bindShowAddFromOther: function() {
        $("a[id^='o']").unbind("mouseover")
        $("a[id^='o']").mouseover(function() {
            var spanadd = "<span id=\"spanadd\"><a href=\"#\" id=\"addFother\"><img src=\"/Image/add3.gif\" id=\"add\" alt=\"添加到我的上网入口\" title=\"添加到我的上网入口\" id=\"od\" /></a></span>";
            $("#spanadd").remove();
            $("#" + this.id).after(spanadd);
            $("#addFother").attr("name", this.id.substring(1));
            rukou.bindAddFromOther();
            return false;
        });
    },

    bindAddFromOther: function() {
        $("a[id^='addFother']").unbind("click")
        $("a[id^='addFother']").click(function() {

            var id = this.id;
            $.ajax({
                type: "POST",
                url: "/Ajax/AddFromOther",
                data: { entryid: this.name },
                success: function(data, textStatus) {
                    alert("已经成功添加到你的上网入口");
                }
            });
            return false;
        });
    },

    bindClearAlertEvent: function() {
        $("#clearAlert").unbind("click")
        $("#clearAlert").click(function() {
            $.ajax({
                type: "POST",
                url: "/Ajax/ClearSetHomeAlert",
                data: { entryid: this.id },
                success: function(data, textStatus) {
                    $("#ctl00_alert").toggle();
                }
            });
            return false;
        });
    },

    bindEditCategoryBlurEvent: function() {
        $("#editCategory").blur(function() {
            if ($.trim(this.value) == "") {
                alert("分类名不能为空");
            }
            else {
                $.ajax({
                    type: "POST",
                    url: "/Ajax/editPrivateEntryCategory",
                    data: { categoryId: $("#editCategory").prev("a").attr("id").substring(4), categoryName: $("#editCategory").attr("value") },
                    success: function(data, textStatus) {
                        eval("data =" + data.toLocaleString());
                        $("#editCategory").prev("a").html(data["cateName"]);
                        $("#privateEntries00").attr("id", "privateEntries" + data["cateId"]);
                        $("#editCategory").prev("a").toggle();
                        $("#editCategory").remove();
                        rukou.showToggleSlidePicturesEvent();
                    }
                });
            }
        });

        $("#editCategory").keypress(function(event) {
            var keynum

            if (window.event) // IE
                keynum = event.keyCode
            else if (event.which) // Netscape/Firefox/Opera
                keynum = event.which
            if (keynum == 13) {
                if ($.trim(this.value) == "") {
                    alert("分类名不能为空");
                }
                else {
                    $.ajax({
                        type: "POST",
                        url: "/Ajax/editPrivateEntryCategory",
                        data: { categoryId: $("#editCategory").prev("a").attr("id").substring(4), categoryName: $("#editCategory").attr("value") },
                        success: function(data, textStatus) {
                            eval("data =" + data.toLocaleString());
                            $("#editCategory").prev("a").html(data["cateName"]);
                            $("#privateEntries00").attr("id", "privateEntries" + data["cateId"]);
                            $("#editCategory").prev("a").toggle();
                            $("#editCategory").remove();

                            //重新计算categories 这个div，以及分割线div的宽度
                            rukou.showToggleSlidePicturesEvent();
                        }
                    });
                }
            }
        });
    },

    initNewAddedTab: function() {
        var tabs = document.getElementById("categories").childNodes;
        NDrag.tabs = [];
        for (var i = 0; i < tabs.length; i++) {
            if (tabs[i].nodeName.toLowerCase() == "a" && tabs[i].id != "addCategory") {
                NDrag.tabs.push(new tab(tabs[i]));
            }

        } //初始化所有的tab页标签

        var pages = document.getElementById("entries");
        NDrag.pages = [];
        for (var i = 0; i < pages.childNodes.length; i++) {
            if (pages.childNodes[i].nodeName.toLowerCase() == "div" && pages.childNodes[i].id.match(/^privateEntries/)) {
                NDrag.pages.push(pages.childNodes[i]);
            }
        } //找到所有的页
        for (var i = 0; i < NDrag.tabs.length; i++) {
            if (NDrag.pages[i]) {
                var page = NDrag.pages[i]; //page
                NDrag.tabs[i].page = page;
                page.tab = NDrag.tabs[i]; //page和tab可以互相引用
            }
        }
    },

    bindNewCategoryBlurEvent: function() {
        $("#newCategory").unbind("blur");
        $("#newCategory").blur(function() {
            if ($.trim(this.value) == "") {
                $("#newCategory").prev("a").remove();
                $("#newCategory").remove();
                $("#privateEntries00").remove();
                NDrag.tabs.pop();
            }
            else {
                $.ajax({
                    type: "POST",
                    url: "/Ajax/addPrivateEntryCategory",
                    data: { categoryName: $("#newCategory").attr("value") },
                    success: function(data, textStatus) {
                        eval("data =" + data.toLocaleString());
                        $("#cate00").toggle();
                        $("#cate00").html($("#newCategory").attr("value"));
                        $("#cate00").attr("id", "cate" + data["cateId"]);
                        $("#privateEntries00").attr("id", "privateEntries" + data["cateId"]);
                        $("#newCategory").remove();

                        rukou.initNewAddedTab();

                        if ($("#categories").css("width") > $("#categories-Container").css("width"))
                            document.getElementById('categories-Container').scrollLeft += 30;

                        //把新增的分类添加到NDrag.categories中
                        var value = categories;
                        var obj = eval('(' + value + ')');
                        var newObj = [];
                        for (var i = 0; i < obj.categories.length; i++) {
                            newObj.push("\"" + obj.categories[i] + "\"");
                        }
                        newObj.push("\"" + data["cateId"] + "-" + data["cateName"] + "\"");
                        categories = "{\"categories\":[" + newObj.toString() + "]}";

                        rukou.showToggleSlidePicturesEvent();
                    }
                });
            }
        });

        $("#newCategory").keypress(function(event) {
            var keynum

            if (window.event) // IE
                keynum = event.keyCode
            else if (event.which) // Netscape/Firefox/Opera
                keynum = event.which
            if (keynum == 13) {
                if ($.trim(this.value) == "") {
                    $("#newCategory").prev("a").remove();
                    $("#newCategory").remove();
                    $("#privateEntries00").remove();
                    NDrag.tabs.pop();
                }
                else {
                    $.ajax({
                        type: "POST",
                        url: "/Ajax/addPrivateEntryCategory",
                        data: { categoryName: $("#newCategory").attr("value") },
                        success: function(data, textStatus) {
                            eval("data =" + data.toLocaleString());
                            $("#cate00").toggle();
                            $("#cate00").html($("#newCategory").attr("value"));
                            $("#cate00").attr("id", "cate" + data["cateId"]);
                            $("#privateEntries00").attr("id", "privateEntries" + data["cateId"]);
                            $("#newCategory").remove();


                            rukou.initNewAddedTab();

                            if ($("#categories").css("width") > $("#categories-Container").css("width"))
                                document.getElementById('categories-Container').scrollLeft += 30;

                            //把新增的分类添加到NDrag.categories中
                            var value = categories;
                            var obj = eval('(' + value + ')');
                            var newObj = [];
                            for (var i = 0; i < obj.categories.length; i++) {
                                newObj.push("\"" + obj.categories[i] + "\"");
                            }
                            newObj.push("\"" + data["cateId"] + "-" + data["cateName"] + "\"");
                            categories = "{\"categories\":[" + newObj.toString() + "]}";

                            rukou.showToggleSlidePicturesEvent();
                        }
                    });
                }
            }
        });
    },

    bindAddCategoryEvent: function() {
        $("#addCategory").unbind("click")
        $("#addCategory").click(function() {
            $("#addCategory").before("<a href='#'   id='cate00'></a><input type='text' id='newCategory'  style='height:20px;width:100px;' />");
            $("#cate00").toggle();
            $("#Scrollbar-Container").before("<div id=\"privateEntries00\" class=\"privateEntries\"></div>");

            NDrag.tabs.push(new tab(document.getElementById("cate00")));


            document.getElementById('categories-Container').scrollLeft += 30;

            $("#cate00").click();
            if (!$.browser.mozilla) {
                $("#newCategory").focus();
                document.getElementById("newCategory").focus();
            }
            rukou.bindNewCategoryBlurEvent();
            rukou.showToggleSlidePicturesEvent();
            return false;
        });
    },

    bindCategoryDoubleClickEvent: function() {
        $("a[id^='cate']").unbind("dblclick")
        $("a[id^='cate']").dblclick(function() {
            $("#" + this.id).after("<input type='text' id='editCategory' value='" + this.innerHTML + "' style='width:" + this.offsetWidth + "' />");
            $("#" + this.id).toggle();
            $("#editCategory").focus();
            document.getElementById("editCategory").focus();
            rukou.bindEditCategoryBlurEvent();
            rukou.showToggleSlidePicturesEvent();
            return false;
        });
    },


    showToggleSlidePicturesEvent: function() {
        var w = 0;
        var categories = $('#categories').children();
        $.each(categories, function(i, c) {
            w += parseInt(c.offsetWidth) + 4;
        });

        $("#categories").css("width", w);

        if (w > 700) {
            $("#goleft").css("display", "block");
            $("#goright").css("display", "block");
        }
    },

    bindDeletePrivateEntryCategoryEvent: function() {
        $("#deleteCategory").click(function() {
            if ($("#privateEntries" + this.name + " > div").html() == null || $("#privateEntries" + this.name + " > div").html() == "") {
                $.ajax({
                    type: "POST",
                    url: "/Ajax/deletePrivateEntryCategory",
                    data: { categoryId: this.name },
                    success: function(data, textStatus) {
                        eval("data =" + data.toLocaleString());
                        $("#cate" + data["categoryId"]).remove();
                        $("#privateEntries" + data["categoryId"]).remove();
                        $("#deleteCategoryArea").remove();
                        rukou.initNewAddedTab();

                        //从NDrag.categories中移除刚刚删除的分类
                        var value = categories;
                        var obj = eval('(' + value + ')');
                        var newObj = [];
                        for (var i = 0; i < obj.categories.length; i++) {
                            if (obj.categories[i] != data["categoryId"] + "-" + data["categoryName"])
                                newObj.push("\"" + obj.categories[i] + "\"");
                        }
                        categories = "{\"categories\":[" + newObj.toString() + "]}";
                    }
                });
            }
            else {
                TINY.box.show(rukou.message.replace("message","请将该分类下所有网站入口移到别的分类下，然后才能删除"),0,0,0,0);
                $("#deleteCategoryArea").remove();
            }
            return false;
        });
    },
    
    bindMenu:function(){
        $("#menu").mouseover(function(){
            rukou.showMenu();
        });
        $("#menu").mouseout(function(){
             rukou.timer = setTimeout(rukou.hideMenu, 200);
        });
        $("#menulist").mouseover(function(){
            rukou.showMenu();
        });
        $("#menulist").mouseout(function(){
              rukou.timer = setTimeout(rukou.hideMenu, 200);
        });
    },
    
    showMenu:function(){
        $("#menu").attr("class","menu_border");
        $("#menulist").show();
       if(rukou.timer)
        {
            clearTimeout(rukou.timer);
            rukou.timer = null;
        }
    },
    
    hideMenu:function(){
        if(rukou.timer)
       {
           clearTimeout(rukou.timer);
           rukou.timer = null;
       }
       $("#menu").attr("class","");
        $("#menulist").hide();
    },
    
    
    clearHomeSettingShow:function(){
        $.ajax({
            type: "POST",
            url: "/Ajax/clearHomeSettingShow",
            data: { },
            success: function(data, textStatus) {
                $("#ShowHomeSetting").remove();
            }
        });
    },
    
    
    entryOrderSave : function() {//将入口排序结果保存到数据库
        if($("#orderChanged") && $("#orderChanged").attr("value")!=""){
            var orderString = "";
            var cates = $("div[id^='privateEntries']");
            for(var i=0;i<cates.length;i++){
                var entries = $(cates[i]).children();
                for(var k=0;k<entries.length;k++){
                    orderString += (orderString==""?"":",") + $(entries[k]).find(".displaynone").html().split('|')[1] + "-" + (k+1);
                }
            }
            $.ajax({
                type: "POST",
                url: "/Ajax/saveEntryOrder",
                data: { orderString: orderString },
                success: function(data, textStatus) {
                }
            });
       }
    },
    
    footerPosition:function(){
         var clientHeight = document.documentElement.clientHeight - 100;
         $('#content').css("min-height",clientHeight);
         if($.browser.msie && $.browser.version == "6.0")
         {
             $('#content').attr("style","height:" +clientHeight + "px");
         }
         
         $("#footer").show();
    },
    
    goleft: function() {
        document.getElementById('categories-Container').scrollLeft -= 1;
    },

    goright: function() {
        document.getElementById('categories-Container').scrollLeft += 1;
    },
    bindGoLeftEvent: function() {
        $("#goleft").click(function() {
            document.getElementById('categories-Container').scrollLeft -= 30;
        });

        $("#goleft").mouseover(function() {
            MyMar = setInterval(rukou.goleft, 1);
        });

        $("#goleft").mouseout(function() {
            clearInterval(MyMar);
        });
    },
    bindGoRightEvent: function() {
        $("#goright").click(function() {
            document.getElementById('categories-Container').scrollLeft += 30;
        });

        $("#goright").mouseover(function() {
            MyMar = setInterval(rukou.goright, 1);
        });

        $("#goright").mouseout(function() {
            clearInterval(MyMar);
        });
    }
    
}


var tab=function(tabElm){
	    var self = this;
	    this.page = null;
	    this.elm = tabElm;
	    this.select = function(){
		    if(!this.page)
			    return;
    			
    	    $("#dragItem").hide();
    	    
	        for(var i=0;i<NDrag.pages.length;i++){
	            NDrag.pages[i].style.display = "none";
	        }
    	    
		    if(NDrag.selectedTab){
			    NDrag.selectedTab.elm.className = "";
			    NDrag.selectedTab.page.style.display = "none";
		    }
    		
		    this.elm.className = "current";
		    this.page.style.display = "block";
		    NDrag.selectedTab = this;
	    }
	    this.elm.onmouseover = function(){
	        if($("#otherview").attr("value")=="False")//不是查看别人的上网入口时
	        {
	            var setting = "<span id=\"deleteCategoryArea\"><a href=\"#\" id=\"deleteCategory\"><img src=\"Image/Delete21.gif\"  alt=\"删除分类\" title=\"删除分类\"  /></a></span>";
                $("#deleteCategoryArea").remove();
                $("#categories-Container").append(setting);
                var ele = document.getElementById(this.id);
                var rect = ele.getBoundingClientRect();  
                
                $("#deleteCategoryArea").css("position","absolute");
                 $("#deleteCategoryArea").css("top",(rect.top-8) + "px");
                  $("#deleteCategoryArea").css("left",(rect.left+(parseInt(ele.offsetWidth) - 5)/2) + "px");
                $("#deleteCategory").attr("name",this.id.substring(4));
                rukou.bindDeletePrivateEntryCategoryEvent();
            }
            return false;
	    }
	    this.elm.onclick = function(){
	        self.select();
	        NDrag.init(this.id.substring(4));
		    return false;
	    }
}


$(document).ready(function() {

     rukou.footerPosition();
     
     rukou.bindStyleChangeEvent();
     rukou.bindMenu();
     rukou.bindAddEvent();
    
    if (typeof($("#categoryArea")) != 'undefined' && $("#categoryArea").length > 0) {
        
        $($("#categories > a")[0]).select();
        
        //默认给第一个分类初始化拖拽事件
        NDrag.init($($("#categories > a")[0]).attr("id").substring(4));
        NDrag.initCategories();
        
        rukou.bindGoLeftEvent();
        rukou.bindGoRightEvent();

        if ($("#aEntryAdding") && $("#aEntryAdding").length > 0) {
            
            rukou.bindAddEvent();

            rukou.bindUpdateEntryEvent();

            rukou.bindAddCategoryEvent();

            rukou.bindCategoryDoubleClickEvent();

            rukou.showToggleSlidePicturesEvent();
            
            if($("#otherview") && $("#otherview").attr("value")=="False") {
               window.onbeforeunload = rukou.entryOrderSave;
            }
          
        }
    }

    rukou.bindAddPrivateEntry();

    rukou.bindShowAddFromOther();
})
